qx.Class.define("rocketspocket.ui.twitter.TwitterService",
{
	extend : qx.core.Object,
	properties : {
		tweets : {
			nullable: true,
			event: "changeTweets"
		}
	},
	
	events : {
		"postOk" : "qx.event.type.Event"
	},
	
	members :
	{
		fetchTweets : function(username, password) {
			if (this.__store == null) {
				var url = "http://api.twitter.com/1/statuses/public_timeline.json";
//				var query = "select * from twitter.user.timeline where id='wittemann'";
				var login = "";
				if (username != null) {
					login = username + ":" + password + "@";
					url = "http://" + login + "twitter.com/statuses/friends_timeline.json";
				}
				this.__store = new qx.data.store.Jsonp(url, null, "callback");
//				this.__store = new qx.data.store.Yql(query);
				this.__store.bind("model", this, "tweets");
			} else {
				this.__store.reload();
			}
		},
		
		post : function(message, username, password) {
			// redirect to twitter because an OAuth login would be too much for this
			// tutorial
			window.open("http://twitter.com/?status=" + encodeURIComponent(message));
		}
	}
});